package com.pap.rabbitmq.config;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.core.MessageProperties;

/**
 * 实现一个 MessagePostProcessor， 设置编码格式和过期时间 如果消息超过过期时间，则可以按照约定，进入到死信队列中
 * 
 * @author alexgaoyh
 *
 */
public class UTFMessagePostProcessor implements MessagePostProcessor {

	@Override
	public Message postProcessMessage(Message message) throws AmqpException {
		MessageProperties messageProperties = message.getMessageProperties();
		// 设置编码
		messageProperties.setContentEncoding("utf-8");
		// 设置过期时间20*1000毫秒
		messageProperties.setExpiration("20000");
		return message;
	}

}
